﻿using Common.Models;
using Common.Utils;
using Microsoft.AspNetCore.Mvc;
using Wallpaper.Models.DTOs.Base;
using Wallpaper.Models.DTOs.Responses;
using Wallpaper.Services.IService;

namespace WallpaperApi.Controllers
{
    [Route("api/favorites")]
    [ApiController]
    public class UserFavoritesController : BaseController
    {
        readonly IUserFavoriteService _userFavoriteService;
        readonly ILogger<UserFavoritesController> _logger;

        public UserFavoritesController(IUserFavoriteService userFavoriteService, ILogger<UserFavoritesController> logger)
        {
            _userFavoriteService = userFavoriteService;
            _logger = logger;
        }

        /// <summary>
        /// 创建用户收藏
        /// </summary>
        /// <param name="wallpaperId"></param>
        /// <returns></returns>
        [HttpPost("{wallpaperId}")]
        public async Task<ApiResponse<Object>> AddFavorite(string wallpaperId)
        {
            bool result= await _userFavoriteService.AddFavoriteAsync(wallpaperId,UserId);
            return ApiResponse<Object>.Success();
        }



        /// <summary>
        /// 用户移除收藏
        /// </summary>
        /// <param name="wallpaperId"></param>
        /// <returns></returns>
        [HttpDelete("{wallpaperId}")]
        public async Task<ApiResponse<Object>> RemoveFavorite(string wallpaperId)
        {
            bool result = await _userFavoriteService.RemoveFavoriteAsync(wallpaperId,UserId);
            return ApiResponse<Object>.Success();
        }

        /// <summary>
        /// 获取个人收藏记录
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResponse<PagedResult<DownloadRecordUserResponse>>> PersonalFavorites([FromQuery] QueryRequest query)
        {
            PagedResult<DownloadRecordUserResponse> result = await _userFavoriteService.UserFavorites(query, UserId);
            return ApiResponse<PagedResult<DownloadRecordUserResponse>>.Success(result);
        }

    }
}
